package com.xinruke.hostels.system.manage.interfaces.api;

import com.xinruke.hostels.common.fallback.FeignFallback;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.system.manage.interfaces.dto.RoomStatusColorAddDefaultDTO;
import com.xinruke.hostels.system.manage.interfaces.dto.RoomTypeDetailQueryDTO;
import com.xinruke.hostels.system.manage.interfaces.dto.RoomTypeDetailQueryResultDTO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.Valid;

/**
 * @ClassName SystemManageFallback
 * @CreateDate 2019/6/28
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 系统管理API熔断
 */
@Component
@Slf4j
public class SystemManageFallback implements FallbackFactory<SystemManageApi> {

    @Autowired
    private FeignFallback feignFallback;

    @Override
    public SystemManageApi create(Throwable throwable) {
        log.error("系统异常", throwable);

        SystemManageApi systemManageApi = new SystemManageApi() {
            @Override
            public ResultVO<RoomTypeDetailQueryResultDTO> getDetail(@Valid RoomTypeDetailQueryDTO underHotelQueryDTO) {
                return feignFallback.doFallback(SystemManageFallback.class, "getDetail", "查询房间类型失败");
            }

            @Override
            public ResultVO addDefault(@Valid RoomStatusColorAddDefaultDTO params) {
                return feignFallback.doFallback(SystemManageFallback.class, "addDefault", "添加默认房态颜色");
            }
        };
        return systemManageApi;
    }
}
